package com.wave12.pro_cart.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wave12.pro_cart.dao.ProCartDetailDao;
import com.wave12.pro_cart.entity.ProCartDetail;
import com.wave12.pro_cart.service.ProCartDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;

/**
 * @Auther: blackcat
 * @Date: 2021-06-02
 * @Description: com.wave12.pro_cart.service.impl
 * @version:
 */
@Service
public class ProCartDetailServiceImpl extends BaseServiceImpl<ProCartDetail>  implements ProCartDetailService {
    private static final Logger logger = LoggerFactory.getLogger(ProCartDetailServiceImpl.class);
    @Autowired
    ProCartDetailDao proCartDetailDao;
    
    @Override
    protected Mapper<ProCartDetail> getMapper() {
        return this.proCartDetailDao;
    }
    
    /**
     * 获取一个补单的详情
     * @param proCartDetail
     * @return
     */
    @Override
    public ProCartDetail getOneProCartDetail(ProCartDetail proCartDetail) {
        return proCartDetailDao.selectOne(proCartDetail);
        //return proCartDetailDao.getOneProCartDetail(proCartDetail);
    }
    
    /**
     * 商家发布一个补单
     * @param proCartDetail
     * @return
     */
    @Override
    public int createOneProCart(ProCartDetail proCartDetail) {
        proCartDetail.setDtGet(new Date());
        proCartDetail.setDtUsed(new Date());
        try{
            return proCartDetailDao.insertSelective(proCartDetail);
        }catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        return 0;
    }
    
    /**
     * 获取最新的补单列表
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<ProCartDetail> getNewProCartList(Integer page,Integer size) {
        PageHelper.startPage(page,size);
        return new PageInfo<ProCartDetail>(proCartDetailDao.selectAll());
    }
    
    /**
     * 更新一个补单的资料
     * @param proCartDetail
     * @return
     */
    @Override
    public int updateOneProCart(ProCartDetail proCartDetail) {
        proCartDetail.setDtUsed(new Date());
        try{
            return proCartDetailDao.updateByPrimaryKey(proCartDetail);
        }catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
        return 0;
    }
}
